package com.simple.datax.bo.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.simple.datax.bo.IDataxFlowBO;
import com.simple.datax.dao.IDataxFlowActorsDAO;
import com.simple.datax.dao.IDataxFlowDAO;
import com.simple.datax.vo.DataxFlowActorsVO;
import com.simple.datax.vo.DataxFlowIdVO;
import com.simple.datax.vo.DataxFlowVO;
import com.simple.util.object.PageInfoBean;

@Service("dataxFlowBO")
@Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class})
public class DataxFlowBOImpl implements IDataxFlowBO {

	@Autowired
	private IDataxFlowDAO dataxFlowDAO;
	@Autowired
	private IDataxFlowActorsDAO dataxFlowActorsDAO;
	

	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class})
	public void add(DataxFlowVO dataxFlowVO,List<DataxFlowActorsVO> listFlowActors) {
		dataxFlowDAO.saveOrUpdate(dataxFlowVO);
		for(int i=0;i<listFlowActors.size();i++){
			dataxFlowActorsDAO.saveOrUpdate(listFlowActors.get(i));
		}
		
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class})
	public void del(DataxFlowIdVO dataxFlowIdVO) {
		DataxFlowVO dataxFlowVO=findById(dataxFlowIdVO);
		dataxFlowVO.setStatus(BigDecimal.valueOf(3));
		dataxFlowDAO.saveOrUpdate(dataxFlowVO);
	}

	@Override
	public DataxFlowVO findById(DataxFlowIdVO id) {
		return dataxFlowDAO.findById(id);
	}

	@Override
	public List<DataxFlowVO> findDataxFlowVOByPage(PageInfoBean pageInfoBean,String flowIdSelect,
			String originateCopSelect, String eNameSelect,String statusSelect
			) {
		return	dataxFlowDAO.findDataxFlowVOByPage(pageInfoBean, flowIdSelect, originateCopSelect, eNameSelect,statusSelect);
	}

	@Override
	public String generateId() {
		return dataxFlowDAO.generateId();
	}

	@Override
	public boolean checkExistFlowName(String flowName) {
		return dataxFlowDAO.checkExistFlowName(flowName);
	}

}
